package com.pinyougou.shop.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class LoginController {

    /** 显示登录用户名 */
    @GetMapping("/showLoginName")
    public Map<String,String> showLoginName(){

        SecurityContext context = SecurityContextHolder.getContext();
        Authentication authentication = context.getAuthentication();
        String loginName = authentication.getName();

        //创建一个map集合，存储登录名，作用是能在页面获取name所对应的值
        Map<String,String> data =new HashMap<>();
        data.put("loginName",loginName);

        return data;

        
    }
}
